//
//  CountDownViewController.m
//  SHWheel
//
//  Created by YYKJ on 2020/10/19.
//  Copyright © 2020 YYKJ. All rights reserved.
//

#import "CountDownViewController.h"
#import <POP.h>

@interface CountDownViewController ()

@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation CountDownViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    
    CGFloat count = 180;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, SCREEN_WIDTH, 50)];
    label.font = [UIFont boldSystemFontOfSize:20];
    label.text = [NSString stringWithFormat:@"%02d:%02d:%02d",(int)count/60,(int)count%60,(int)(count*100)%100];
    [self.view addSubview:label];
    
    POPAnimatableProperty *prop = [POPAnimatableProperty propertyWithName:@"count down" initializer:^(POPMutableAnimatableProperty *prop) {
        prop.writeBlock = ^(id obj, const CGFloat *values) {
             label.text = [NSString stringWithFormat:@"%02d:%02d:%02d",(int)values[0]/60,(int)values[0]%60,(int)(values[0]*100)%100];
        };
    }];
    
    POPBasicAnimation *anBasic = [POPBasicAnimation linearAnimation];   //秒表当然必须是线性的时间函数
    anBasic.property = prop;    //自定义属性
    anBasic.fromValue = @(180);   //从0开始
    anBasic.toValue = @(0);  //180秒
    anBasic.duration = 3*60;    //持续3分钟
    anBasic.beginTime = CACurrentMediaTime() + 1.0f;    //延迟1秒开始
    [label pop_addAnimation:anBasic forKey:@"countdown"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
